//
//  String+LTExtension.swift
//  myMoya
//
//  Created by lete on 2020/4/29.
//  Copyright © 2020 xiaoyi. All rights reserved.
//

import Foundation


////截取字符串
//extension String {
//    public func substring(from index: Int) -> String {
//        if self.count > index {
//            let startIndex = self.index(self.startIndex, offsetBy: index)
//            let subString = self[startIndex..<self.endIndex]
//            return String(subString)
//        } else {
//            return self
//        }
//    }
//}

//MARK: - 字符串为空判断
extension String {
    /// 以下这几种情况都认为的空
    public static func isEmptyString(str: String?) -> Bool {
        if str == nil {
            return true
        } else if (str == "") {
            return true
        } else if (str == "<null>") {
            return true
        } else if (str == "(null)") {
            return true
        } else if (str == "null") {
            return true
        }
        return false
    }
}

//MARK: - 随机大小写英文数字字符串
//String.randomStr(len: 30)
extension String{
    static let random_str_characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    static func randomStr(len : Int) -> String{
        var ranStr = ""
        for _ in 0..<len {
            let index = Int(arc4random_uniform(UInt32(random_str_characters.count)))
            ranStr.append(random_str_characters[random_str_characters.index(random_str_characters.startIndex, offsetBy: index)])
        }
        return ranStr
    }
}


